#include "types.h"
#include "core/Trap.h"
#include "verilated_dpi.h"

#include <functional>

// Core
std::function<void(word_t*)> dpic_set_gpr_ptr_handler;
std::function<void(word_t*)> dpic_set_csr_ptr_handler;
std::function<void(Trap, word_t)> dpic_take_trap_handler;

extern "C" {
    void dpic_set_gpr_ptr(const svOpenArrayHandle r) {
        dpic_set_gpr_ptr_handler((word_t*)(((VerilatedDpiOpenVar*)r)->datap()));
    }

    void dpic_set_csr_ptr(const svOpenArrayHandle r) {
        dpic_set_csr_ptr_handler((word_t*)(((VerilatedDpiOpenVar*)r)->datap()));
    }

    void dpic_take_trap(word_t trap_cause_code, word_t trap_pc) {
        dpic_take_trap_handler((Trap)trap_cause_code, trap_pc);
    }

}
